package interview;

/**
 * description: 安司源科技 输入 abc111aaaaabbaaa，输出连续重复最多的串 aaaaa
 *
 * @author <a href="zhaoyingling12@163.com">simon zhao</a>
 * @since 2023/3/28
 */
public class Test0328 {
    public static void main(String[] args) {
        String input = "abc111aaaaabbaaa";
        // dp[i] 表示当i为止，重复次数最多的连续字母长度
        int[] dp = new int[input.length()];
        char[] chars = input.toCharArray();
        int maxLen = Integer.MIN_VALUE, maxLenIndex = -1;
        for (int i = 0; i < chars.length; i++) {
            if (i == 0) {
                dp[i] = 1;
            }
            if (i != 0 && chars[i] == chars[i - 1]) {
                dp[i] = dp[i - 1] + 1;
            } else {
                dp[i] = 1;
            }
            if (dp[i] > maxLen) {
                maxLenIndex = i;
                maxLen = dp[i];
            }
        }
        System.out.println(input.substring(maxLenIndex - maxLen + 1, maxLenIndex + 1));
    }
}
